package main

import (
	"context"
	"fmt"
	"time"
)

type paramKey struct {
}

func main() {
	c := context.WithValue(context.Background(), paramKey{}, "abc")
	c, cancelFunc := context.WithTimeout(c, 5*time.Second)
	defer cancelFunc()
	mainTask(c)
}

func mainTask(c context.Context) {
	fmt.Printf("main task started with param: %q\n", c.Value(paramKey{}))
	samllTask(c, "task1", 1*time.Second)
	samllTask(c, "task2", 2*time.Second)
}

func samllTask(c context.Context, name string, d time.Duration) {
	fmt.Printf("%s started with param :%q \n", name, c.Value(paramKey{}))
	select {
	case <-time.After(d):
		fmt.Printf("%s done \n", name)
	case <-c.Done():
		fmt.Printf("%s cancelded\n", name)
	}
}
